package course5.com.youkeda.service.impl;

import course5.com.youkeda.exception.ParamNullExcepation;
import course5.com.youkeda.model.User;
import course5.com.youkeda.service.UserService;

import java.util.ArrayList;
import java.util.List;

public class UserServiceImpl implements UserService {
    private  static List<User> USERS=new ArrayList<>();
static {
    User user = new User();
    user.setNickName("爱吹风的牛");
    user.setUserName("niu");
    user.setPassword("Niu123");
    USERS.add(user);

    user = new User();
    user.setNickName("我爱西红柿");
    user.setUserName("xihongshi");
    user.setPassword("Didi5");
    USERS.add(user);
}

    @Override
    public User login(String userName, String password) throws ParamNullExcepation {
        if (userName==null){
            throw new ParamNullExcepation("用户名不空");
        }
        if (password==null){
            throw new ParamNullExcepation("密码为空");
        }
        for (User user:USERS
             ) {
            if (user.getUserName().equals(userName)&&user.getPassword().equals(password)){
                return user;
            }
        }
        return null;
    }
}
